<?php

namespace mpend\modules\commission\models;

/**
 * 分销中心会员信息基础
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class MarketOrderSearch extends \common\models\member\MemberMarketLog {

    public $rectime = null;

    /**
     * 分销中心会员信息基础
     *
     * @author emhome <emhome@163.com>
     * @since 1.0
     */
    public function buildQuery() {
        $query = static::find()->active(static::STATUS_ACTIVE)->andWhere([
            'user_id' => $this->user_id,
        ]);
        $query->with(['orderUser']);
        if ($this->rectime !== null) {
            $query->andWhere(['>', 'created_at', $this->rectime]);
        }
        $query->addOrderBy([
            'created_at' => SORT_DESC,
        ]);
        return $query;
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'user' => 'orderUser',
            'price' => function() {
                if ($this->price > 0) {
                    return '+' . number_format($this->price / 100, 2);
                }
                return '0.00';
            },
            'experience' => function() {
                if ($this->experience > 0) {
                    return '经验值 +' . $this->experience . '点';
                }
                return '';
            },
            'status',
            'depend_date' => function() {
                return date('Y-m-d', $this->created_at);
            },
            'created_at',
        ];
    }

}
